﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace DetectApp;

public class Bool2Brush : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if(value is not bool)
            return Binding.DoNothing;

            bool? bvalue = value as bool?;
        if (bvalue == true)
        {
            return Brushes.Green;
        }
        else if (bvalue == false)
        {
            return Brushes.Red;
        }
        else
            return Brushes.Transparent;

    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
public class Bool2Visible : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool bvalue = (bool)value;
        if (bvalue == true)
        {
            return Visibility.Visible;
        }
        else
            return Visibility.Hidden;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
public class List2Str : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is List<DefectCls> list)
        {
            string str1 = string.Empty;
            foreach (var dec in list)
            {
                str1 += dec.DefectName;
                str1 += ",";
            }
            return str1;
        }
        return Binding.DoNothing;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}